class Solution
{
public:
    int hardestWorker(int n, vector<vector<int>> &logs)
    {
        int workCount = logs.size();
        int lastLeave = 0;
        int maxSpan = 0;
        int maxSpanId = -1;
        for (int i = 0; i < workCount; ++i)
        {
            int span = logs[i][1] - lastLeave;
            if (span > maxSpan)
            {
                maxSpan = span;
                maxSpanId = logs[i][0];
            }
            else if (span == maxSpan)
            {
                maxSpanId = min(maxSpanId, logs[i][0]);
            }
            lastLeave = logs[i][1];
        }
        return maxSpanId;
    }
};